package com.example.demo11.untils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class DButils {
    public static String url="jdbc:mysql://localhost:3306/studb";
    public static String user="root";
    public static String password="123456";

    public static void main(String[] args) {
        try {
//            加载数据库驱动
            Class.forName("com.mysql.jdbc.Driver");
//            创建数据库连接
            Connection conn = DriverManager.getConnection(url,user,password);
//            创建statement对象
            Statement statement=conn.createStatement();

            String sql="select * from student";

            ResultSet resultSet = statement.executeQuery(sql);

            while (resultSet.next()){
                System.out.println(resultSet.getString("number"));
                System.out.println(resultSet.getString("name"));
                System.out.println(resultSet.getString("birthday"));
                System.out.println(resultSet.getString("stuclass"));
                resultSet.close();
                statement.close();
                conn.close();

            }

        }
        //大的异常捕获
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}
